package com.it.tydic.estate.common.security;

import com.it.tydic.estate.common.constants.Constants;
import com.it.tydic.estate.module.service.RedisCacheService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Configuration
@EnableWebSecurity
public class LoginOutHandler implements LogoutHandler {

    @Autowired
    private RedisCacheService redisCacheService;

    private static final Logger logger=  LoggerFactory.getLogger(LoginOutHandler.class);

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        request.getSession().removeAttribute(Constants.CURRENTUSER);
       boolean flag= redisCacheService.delete(request.getSession().getId());
       if(flag){
           logger.info("登出成功");
       }
    }
}
